#!/usr/bin/env python
# -*- coding:utf-8 -*-
import uuid
from celery import shared_task
from apps.api import models
from hashlib  import md5

@shared_task
def to_preview_status_task(auction_id):
    models.Auction.objects.filter(id=auction_id).update(status=2)
    models.AuctionItem.objects.filter(auction_id=auction_id).update(status=2)


@shared_task
def to_auction_status_task(auction_id):
    models.Auction.objects.filter(id=auction_id).update(status=3)
    models.AuctionItem.objects.filter(auction_id=auction_id).update(status=3)


@shared_task
def end_auction_task(auction_id):
    models.Auction.objects.filter(id=auction_id).update(status=4)
    models.AuctionItem.objects.filter(auction_id=auction_id).update(status=4)
    # total = 0
    # total_unfortunate_list = []
    # lucky_auction_deposit_id = set()
    # auction_object = models.Auction.objects.filter(id=auction_id).first()
    # item_object_list =
    # models.AuctionItem.objects.filter(auction=auction_object)
    # # 􀮗􁈾􀲅􀹍􁌱􀳌􀟝
    # for item_object in item_object_list:
    # # 􁞴􀝐􀭮􀚹􀳌􀟝􀚊􀕰􀹋􁹛􁘏
    #     lucky_object =models.BidRecord.objects.filter(item=item_object).order_by('-price').first()
    #     # 􀷫􀚊􀕰􀒅􀚞􁁞􁁝
    #     if not lucky_object:
    #         item_object.status = 5
    #         item_object.save()
    #         continue
    #     lucky_object.status = 2
    #     lucky_object.save()
    #     # 􀳌􀟝􀒓􁦡􁗝􀱮􀔻􀕰
    #     item_object.deal_price = lucky_object.price
    #     item_object.save()
    #     # 􀓫􀣋􀒓􀯛􀱮􀔻􁷐
    #     total += lucky_object.price
    #     # 􁞴􀝐􀭮􀚹􁊠􀲁􀔅􀾌 􀳌􀟝/􀓫􀣋 􀶪􀕞􁌱􀗛􁦤􁰂􀩒􁨝
    #     deposit_object = models.DepositRecord.objects.filter(
    #         user=lucky_object.user,
    #         item=item_object,
    #         deposit_type=1).first()
    #     if not deposit_object:
    #         deposit_object = models.DepositRecord.objects.filter(user=lucky_object.user,
    #                                                              auction=auction_object,
    #                                                              deposit_type=2, item__isnull=True).first()
    #
    #     lucky_auction_deposit_id.add(deposit_object.id)
    #
    #     order_object = models.Order.objects.create(
    #         uid=md5(uuid.uuid4()),
    #         user=lucky_object.user,
    #         item=item_object,
    #         deposit=deposit_object,
    #         price=lucky_object.price,
    #     )
